using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestFunc : MonoBehaviour
{
    void Start()
    {
        Queue<string> myQueue = new Queue<string>();
        myQueue.Enqueue("First");
        myQueue.Enqueue("Second");
        myQueue.Enqueue("Third");
        Debug.Log("Peek: " + myQueue.Peek());
        while (myQueue.Count > 0)
        {
            string item = myQueue.Dequeue();
            Debug.Log("Dequeued: " + item);
        }
        Debug.Log("myQueue Nums: " + myQueue.Count);
        // Stack<>
    }
    private void test1()
    {
        // 定义一个接受两个整数参数并返回字符串的 Func
        Func<int, int, string> SumToString = (a, b) => (a + b).ToString();
        string result = SumToString(3, 5); // 返回 "8"
        Debug.Log(result);
        Debug.Log(SumToString.Invoke(6, 6));
        
        // Func 示例  
        Func<int, bool> IsEven = num => num % 2 == 0;
        bool check = IsEven(4); // true 
        
        // Action 示例  
        Action<string> LogMessage = msg => Debug.Log(msg);
        LogMessage("Hello World"); // 输出到控制台
        LoadResource("Assets/Enemy.prefab", () =>
        {
            Debug.Log("加载成功");
            return true;
        });
    }
    public void LoadResource(string path, Func<bool> onComplete)
    {
        StartCoroutine(LoadAsync(path, onComplete));
    }
    private IEnumerator LoadAsync(string path, Func<bool> callback)
    {
        // 模拟异步加载  
        yield return new WaitForSeconds(2);
        bool success = true;
        callback?.Invoke(); // 调用回调函数  
    }
    void Update() { }
}